import { getRoleListApi, getUserListApi } from '@/views/rbac/api/rbac.api';

const state = {
  roleList: [],
  userList: []
};

const mutations = {
  SET_ROLE_LIST(state, data) {
    state.roleList = data;
  },
  SET_USER_LIST(state, data) {
    state.userList = data;
  }
};

const actions = {
  getRoleList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getRoleListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_ROLE_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getUserList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getUserListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_USER_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
